package com.spring.framework.config.autowired.model;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Component
public class AutowiredAllDemo {

    //获取该类型的全部bean，会向下兼容

    @Autowired
    private AutowiredAllA[] autowiredAllAS;

    @Autowired
    private AutowiredAllB[] autowiredAllBS;

    private AutowiredAllC[] autowiredAllCS;

    @Autowired
    private List<AutowiredAllA> autowiredAllAList;

    private Set<AutowiredAllA> autowiredAllASet;

    /**
     * Map的key为String类型，就是bean的名字
     */
    @Autowired
    private Map<String, AutowiredAllA> autowiredAllAMap;

    /**
     * 支持方法注入
     */
    @Autowired
    public void setAutowiredAllASet(Set<AutowiredAllA> autowiredAllASet) {
        this.autowiredAllASet = autowiredAllASet;
    }

    /**
     * 支持构造器注入
     */
    public AutowiredAllDemo(AutowiredAllC[] autowiredAllCS) {
        this.autowiredAllCS = autowiredAllCS;
    }

    @Component
    public static class AutowiredAllA {
    }

    @Component
    public static class AutowiredAllB extends AutowiredAllA {
    }

    /**
     * 指定最高优先
     */
    @Order(Ordered.HIGHEST_PRECEDENCE)
    @Component
    public static class AutowiredAllC extends AutowiredAllB {
    }


    @Override
    public String toString() {
        return "AutowiredAllDemo{" + "\n" +
                "autowiredAllAS=" + Arrays.toString(autowiredAllAS) + "\n" +
                ", autowiredAllBS=" + Arrays.toString(autowiredAllBS) + "\n" +
                ", autowiredAllCS=" + Arrays.toString(autowiredAllCS) + "\n" +
                ", autowiredAllAList=" + autowiredAllAList + "\n" +
                ", autowiredAllASet=" + autowiredAllASet + "\n" +
                ", autowiredAllAMap=" + autowiredAllAMap +
                '}';
    }
}
